<!-- 新增送修-厂家-未邀标 -->
<template>
	<Card>
		<template #head>
			厂家
		</template>
		<template #body>
			<CellItem required v-model="formData.factory" itemClickType="select-factory" label="维修厂家"></CellItem>
			<CellItem v-model="formData.user" ref="User" label="厂家代表" :customActionSheetList="CustomActionSheetList"></CellItem>
			<CellField v-model="formData.phone" label="联系电话"></CellField>
		</template>
	</Card>
</template>

<script>
	import Card from '@/components/card/components/cardBaseWrapper.vue'
	import {
		searchFactoryPerson
	} from '@/apis/common.js'
	export default {
		components: {
			Card,

		},
		computed: {
			CustomActionSheetList() {
				this.$nextTick(() => {

					this.$refs.User.resetInit()
				})
				return this.factoryPersonList.map((item) => {
					return {
						name: item.name,
						value: item.id,
						other: item.mblNo
					}
				})
			}
		},

		data() {
			return {
				factoryPersonList: [],
				formData: {
					factory: '',
					user: '',
					phone: '',
				}
			}
		},

		watch: {
			'formData.user'(val) {
				let res = this.CustomActionSheetList.find((item) => item.value == val)
				this.$set(this.formData, 'phone', res.other)
			},
			'formData.factory'(val) {
				searchFactoryPerson(val).then((res) => {
					if (res.code === 0) {
						this.factoryPersonList = res.body.list
						if (this.factoryPersonList.length) {
							let {
								id,
								name,
								mblNo
							} = this.factoryPersonList[0]
							this.$set(this.formData, 'user', id)
							this.$set(this.formData, 'phone', mblNo)
						}
					}
				})
			}
		},
		methods: {
			validate() {
				let msg = ''
				if (this.formData.factory == '') {
					msg = '请选择维修厂家'
				} else {
					msg = ''
				}
				if (!msg) {
					return true
				}
				this.$msg(msg)
				return false
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
